package com.ww.configuration;

import com.ww.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

import java.util.Arrays;
import java.util.List;

@Configuration
@EnableWebMvc
public class WebMvcConfiguration implements WebMvcConfigurer {
    // 拦截器进行配置
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        List<String> list = Arrays.asList("/user/login","/user/register","/pages/index.html");
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/pages/amdin/**")
                .excludePathPatterns(list)
                .order(1);
    }


    // 资源的配置
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //registry.addResourceHandler("/static/**").addResourceLocations("/static/");
        //registry.addResourceHandler("/pages/**").addResourceLocations("/pages/");
        //registry.addResourceHandler("/js/**").addResourceLocations("/static/js/");
        //registry.addResourceHandler("/static/js/**").addResourceLocations("/static/js/");
        //registry.addResourceHandler("/css/**").addResourceLocations("/static/js/");
        //registry.addResourceHandler("/static/css/**").addResourceLocations("/static/css/");
        //registry.addResourceHandler("/bootstrap-4.6.1-dist/**").addResourceLocations("/static/bootstrap-4.6.1-dist/");
        //registry.addResourceHandler("/static/bootstrap-4.6.1-dist/**").addResourceLocations("/static/bootstrap-4.6.1-dist/");
    }


    //页面跳转的配置
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/pages/index").setViewName("index");
        registry.addViewController("/pages/signin").setViewName("signin");
        registry.addViewController("/pages/register").setViewName("register");
    }

}